// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class FINANCIAL_COMMON_ORDER_DFT_P11 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("211 ORC",211)]
  	    [HL7Field(HL7Version.v24, 211, HL7Repeat.False, HL7Required.False,"ORC")]
	    public ORC ORC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("212 FINANCIAL_ORDER",212)]
  	    [HL7Field(HL7Version.v24, 212, HL7Repeat.False, HL7Required.False,"FINANCIAL_ORDER_DFT_P11")]
	    public FINANCIAL_ORDER_DFT_P11 FINANCIAL_ORDER {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("216 FINANCIAL_OBSERVATION",216)]
  	    [HL7Field(HL7Version.v24, 216, HL7Repeat.False, HL7Required.False,"FINANCIAL_OBSERVATION_DFT_P11")]
	    public FINANCIAL_OBSERVATION_DFT_P11 FINANCIAL_OBSERVATION {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			ORC = PopSegmentParseAndCheckRequired<ORC>(availableData, options, "ORC");
			FINANCIAL_ORDER = ProcessGroup<FINANCIAL_ORDER_DFT_P11>(availableData, options, "FINANCIAL_ORDER");
			FINANCIAL_OBSERVATION = ProcessGroup<FINANCIAL_OBSERVATION_DFT_P11>(availableData, options, "FINANCIAL_OBSERVATION");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isORC = availableData.StartsWith("ORC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("ORC", options.Version) || isORC) {
				return isORC;
			}
			FINANCIAL_ORDER_DFT_P11 testFINANCIAL_ORDER_DFT_P11 = new FINANCIAL_ORDER_DFT_P11();
			bool grpCCFINANCIAL_ORDER_DFT_P11 = (testFINANCIAL_ORDER_DFT_P11.CanConsume(availableData, options));
			if (IsRequired("FINANCIAL_ORDER", options.Version) || grpCCFINANCIAL_ORDER_DFT_P11) {
				return grpCCFINANCIAL_ORDER_DFT_P11;
			}
			FINANCIAL_OBSERVATION_DFT_P11 testFINANCIAL_OBSERVATION_DFT_P11 = new FINANCIAL_OBSERVATION_DFT_P11();
			bool grpCCFINANCIAL_OBSERVATION_DFT_P11 = (testFINANCIAL_OBSERVATION_DFT_P11.CanConsume(availableData, options));
			if (IsRequired("FINANCIAL_OBSERVATION", options.Version) || grpCCFINANCIAL_OBSERVATION_DFT_P11) {
				return grpCCFINANCIAL_OBSERVATION_DFT_P11;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "FINANCIAL_COMMON_ORDER";
			}
        }

        static FINANCIAL_COMMON_ORDER_DFT_P11() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(FINANCIAL_COMMON_ORDER_DFT_P11));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (ORC != null) {
			string segmentValue = ORC.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (FINANCIAL_ORDER != null) {
			string segmentValue = FINANCIAL_ORDER.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (FINANCIAL_OBSERVATION != null) {
			string segmentValue = FINANCIAL_OBSERVATION.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

